package com.jye.cloud.user.controller;


import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jye.cloud.domain.JsonResult;
import com.jye.cloud.domain.User;
import com.sun.org.glassfish.gmbal.ParameterNames;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/user")
public class UserNacosController {

    @Value("${server-url.cloud-provider-user}")
    private String serverUrl;

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/test")
    public String test(){
       return serverUrl;
    }

    @GetMapping("/findUserById")
    public JsonResult findUserById(int id){
        return restTemplate.getForObject(serverUrl+"/user/findUserById?id="+id,JsonResult.class);
    }

    @GetMapping("/findUserLoginHistoryById")
    public JsonResult findUserLoginHistoryById(int id){
        return restTemplate.getForObject(serverUrl+"/user/findUserLoginHistoryById?id="+id,JsonResult.class);
    }

    @GetMapping("/isExitUsername")
    public JsonResult isExitUsername(String username){
        return restTemplate.getForObject(serverUrl+"/user/isExitUsername?username="+username,JsonResult.class);
    }

    @GetMapping("/login")
    public JsonResult login(User user){
        return restTemplate.getForObject(serverUrl+"/user/login?username="+user.getUsername()+"&password="+user.getPassword(),JsonResult.class);
    }

    @PostMapping("/register")
    public JsonResult register(User user){
        return restTemplate.postForObject(serverUrl+"/user/register",user,JsonResult.class);
    }


}
